import pathToRegexp from 'path-to-regexp/index';
import {getStorage,postStorage} from 'services/app';
export default {
    namespace: 'storage',
    state: {
        pages:1,
        record:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //查看登录状态
        *getStorage ({ payload }, { call, put }){
            const {data,total} = yield call(getStorage, payload);
            yield put({ type: 'save', payload: {getStorageData:data,total:total,pages:payload.pageNumber}});
        },
        //新增库存地点
        *postStorage ({ payload }, { call, put }){
            const data = yield call(postStorage, payload);
            if(data.code == '0'){
                yield put({ type: 'save', payload: {pages:0,view:false}});
            }
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
